Promise.retry = (callback, retryTime) => {
    // const curPromise = callback()
    return new Promise((resolve, reject) => {
        callback().then(
            (value) => {
                resolve(value)
            },
            (reason) => {
                // 超过重试次数
                if (!retryTime) reject(reason)
                // 没有超过重试次数
                else{
                    // 继续调用retry函数
                    Promise.retry(callback, --retryTime).then(resolve, reject)
                }
        })
    })
}
let count = 0
Promise.retry(() => {
  console.log(++count)
    //? 先发失败的 到一定次数后发成功的
  return count === 5 ? Promise.resolve('success') : Promise.reject('failed')
}, 3).then((value) => console.log(value),(error) => console.log(error))
